const app = getApp();
import requset from "/utils/request";
import clock from "/api/clock/index"
import { showToast } from "/utils/common";
import { recordType } from "/utils/dictionary";
import { dateFormat } from "/utils/commonMethod";
import { onPlayRecord } from "/utils/common"
Page({
  data: {
    form: {} // 表单数据
  },
  onLoad(option) {
    dd.showLoading({
      content: "加载中..."
    })
    requset({
      url: clock.getVisitRecordDetail,
      data: { id: option && option.id }
    }).then((res) => {
      console.log(res, "详情页");
      if (res.success) {
        let imgList = []
        let voiceNumber= 0;
        let wordageNumber = 0;
        // 处理日期格式
        res.vo.startDate = dateFormat(res.vo.startDate);
        res.vo.endDate = dateFormat(res.vo.endDate);
        // 处理门店图  门店内部图  其它图
        imgList.push(res.vo.shopImg);
        imgList.push(res.vo.shopInteriorImg);
        imgList.push(res.vo.otherImg);
        res.vo.imgList = imgList;
        // 处理音频播放动画
        res.vo.visitRecordContentList.forEach((item) => {
          item.audioPlayFlag = item.sysEnclosureVO && false // 语音播放状态
        })
        // 处理语音记录条数 和文字记录条数

        console.log(res.vo, "res.vo")
        this.setData({
          form: Object.assign(this.data.form, res.vo)
        })
      }
      dd.hideLoading();
    })
  },
  onShow() {
  },
  viewImage(e) {
    // 图片预览
    console.log(this.data.form.imgList.map((item) => item && item.fileUrl),"ingllIST")
    dd.previewImage({
      current: e.currentTarget.dataset.index,
      urls: this.data.form.imgList.map((item) => item && item.fileUrl),
    });
  },
  // 音频播放
  audioPlay(e) {
    // console.log(e, "eeee");
    this.data.form.visitRecordContentList.forEach((item,index) => {
      if (index ===e.currentTarget.dataset.index) {
        item.audioPlayFlag = true
      } else {
         item.audioPlayFlag = false;
      }
    })
    console.log(this.data.form.visitRecordContentList, "visitRecordContentList");
    this.setData({
      "form.visitRecordContentList": this.data.form.visitRecordContentList
    })
    // 音频
    onPlayRecord(e.currentTarget.dataset.url).then((res) => {
      this.data.form.visitRecordContentList[e.currentTarget.dataset.index].audioPlayFlag = false;
      this.setData({
        "form.visitRecordContentList": this.data.form.visitRecordContentList
      })
    })
  },
  onUnload() {
    // 页面被关闭
    this.setData({
       form: {} 
    })
  },
});
